import useAuthButton from '@/hooks/useAuthButton';
import { ButtonProps } from 'antd';
import { JSX } from 'react';

type ButtonComponent = React.FC<ButtonProps> | JSX.Element | null;
interface ButtonPerProps {
  btn: string;
  Comp: ButtonComponent;
}

const ButtonPer = ({ btn, Comp }: ButtonPerProps): JSX.Element | null => {
  const { BUTTON } = useAuthButton();
  // 如果but为空
  if (!btn) {
    return <>{Comp}</>;
  }
  // BUTTON 是否为空对象
  if (Object.keys(BUTTON).length === 0) {
    return null;
  }
  if (BUTTON && BUTTON.includes(btn) && Comp) {
    return <>{Comp}</>;
  }

  return null;
};

export default ButtonPer;
